package com.glorysoft.hlgdpda.ui.materialandtool.viewmodel

import android.widget.EditText
import com.glorysoft.hlgdpda.base.BaseViewModel
import com.glorysoft.hlgdpda.entity.ui.CallObserveBean
import com.glorysoft.hlgdpda.model.TaskRepository
import com.google.gson.JsonObject

/**
 * FileName: CarrierBindViewModel
 * Author: XJH
 * Date: 2021/7/19 16:54
 * Description:
 * History:
 */
class CarrierBindViewModel : BaseViewModel() {

    private val carrierRepository = TaskRepository()


    fun bindCarrierToLot(carrier: String, lot: String) {
        val map = JsonObject()
        map.addProperty("LOTID", lot)
        map.addProperty("CARRIERID", carrier)
        launchOnlyResult({
            carrierRepository.carrierBindLot(map)
            defUI.callObserve.call()
        })

    }

    fun unBindCarrierToLot(carrier: String, lot: String) {
        val map = JsonObject()
        map.addProperty("LOTID", lot)
        map.addProperty("CARRIERID", carrier)
        launchOnlyResult({
            carrierRepository.carrierUnBindLot(map)
            defUI.callObserve.call()
        })

    }

    fun searchCarrierInfo(carrier: String, et : EditText) {
        val map = JsonObject()
        map.addProperty("CARRIERID", carrier)
        launchOnlyResult({
            val lotInfo = carrierRepository.getLotInfoByCarrier(map)
            et.setText(lotInfo.LOT.LOTID)

        })
    }

}